#!/bin/sh

# Script name: readex2.sh

cp /etc/hosts /tmp/hosts2
grep -v '^#' /tmp/hosts2 > /tmp/hosts3 # Strip out comment lines

exec 3< /tmp/hosts3	# fd 3 is an input file /tmp/hosts3
exec 4> /tmp/hostsfinal	# fd 4 si output file /tmp/hostsfinal

read <& 3 addr1	name1 alias # read from fd 3

read <& 3 addr2 name2 alias # read from fd 4

exec 3<&- #Close fd 3

echo $name1 $addr1 >& 4	# write to fd 4 (do not write aliases)
echo $name2 $addr2 >& 4	# write to fd 4 (do not write aliases)


exec 4<&- #Close fd 4 
